const db = require("../db/index")

exports.getInfo = (req,res)=>{
  // const sql = `select * from test_table where status=${req.body.status} and age%2=0`
  const sql =`select * from test_table`
  db.query(sql,req,(err,results)=>{
    if (err) {
      return res.cc(err)
    }
    res.send({
      data:results,
    })
  }
)}

exports.addInfo = (req,res)=>{
  // console.log(res);
  // const info={id:6,name:"孙悟空",age:24,work:'保镖'}
  const sql = `insert into test_table (name,age) values ('a',1),('b',2),('c',3)`
  db.query(sql,req.body,(err,results)=>{
    if (err) {
      return res.cc(err)
    }
    res.send({
      data:results,
    })
  }
)}

exports.modifyInfo = (req,res)=>{
  const sql =`update test_table set ? where id=?`
  db.query(sql,[req.body,req.body.id],(err,results)=>{
    if (err) {
      return res.cc(err)
    }
    // if (results.) {
      
    // }
    res.send({
      data:results,
    })
  }
)}  
  

